/*
 *  hackds/corse_design/voldemort_language/main.c
 *
 *  (C) 2011 Harry Wei
 */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <error.h>

#include "./include/vl.h"

int
main(int argc, char *argv[])
{
	int i = 0;
	int r_counter;
	int i_counter;
	char *vol_lan = NULL;
	struct rule *regu = NULL;
	struct mean *implication = NULL;

	if (3 != argc) {
		fprintf(stderr, "Please enter your voldemort files!\n");
		return 1;
	}
	if (rd_file(argv[1], argv[2], &regu, 
		&implication, &r_counter, &i_counter))
		return 1;
	vol_lan = (char *)malloc(sizeof(char) * BUF);
	if (!vol_lan) {
		fprintf(stderr, "Allocate Error!\n");
		return 1;
	}
	if (tran_vol(vol_lan, regu, r_counter))
		return 1;
	printf("%s\n", vol_lan);
#if DEBUG == 1
	for (i = 0; i < r_counter; i++) {
		printf("%c\n", regu[i].upper_ch);
		printf("%s\n", regu[i].reg);
	}
	for (i = 0; i < i_counter; i++) {
		printf("%c\n", implication[i].lower_ch);
		printf("%s\n", implication[i].meaning);
	}
#endif

#if DEBUG == 2	/* Encryption Here */
	while (vol_lan[i]) {
		vol_lan[i] += 1;
		i += 1;
	}
#endif
	if (record(vol_lan, implication, i_counter))
		return 1;
	return 0;
}
